package Utils;

/**
 * Get System Property for the Operating System.<br>And Check the OS
 * Type.<br>This Class has all <b>Methods Static</b>.
 *
 * @author mohamed Tarek Salama
 * @version 1.3 BETA
 */
public class MSJ_SysProperty {

    private static final String line_separator = System.getProperty("line.separator");
    private static final String file_separator = System.getProperty("file.separator");
    private static final String path_separator = System.getProperty("path.separator");
    private static final String os_name = System.getProperty("os.name");
    private static final String os_version = System.getProperty("os.version");
    private static final String os_arch = System.getProperty("os.arch");
    private static final String temp_path = System.getProperty("java.io.tmpdir");
    private static final String user_name = System.getProperty("user.name");
    private static final String user_home = System.getProperty("user.home");
    private static final String user_dir = System.getProperty("user.dir");
    private static final String java_version = System.getProperty("java.version");
    private static final String java_vendor = System.getProperty("java.vendor");
    private static final String java_vm_version = System.getProperty("java.vm.version");
    private static final String java_vm_vendor = System.getProperty("java.vm.vendor");
    private static final String java_vm_name = System.getProperty("java.vm.name");

    public static String getFile_separator() {
        return file_separator;
    }

    public static String getLine_separator() {
        return line_separator;
    }

    public static String getPath_separator() {
        return path_separator;
    }

    public static String getOs_arch() {
        return os_arch;
    }

    public static String getOs_name() {
        return os_name;
    }

    public static String getOs_version() {
        return os_version;
    }

    public static String getTemp_path() {
        return temp_path;
    }

    public static String getUser_dir() {
        return user_dir;
    }

    public static String getUser_home() {
        return user_home;
    }

    public static String getUser_name() {
        return user_name;
    }

    public static String getJava_vendor() {
        return java_vendor;
    }

    public static String getJava_version() {
        return java_version;
    }

    public static String getJava_vm_name() {
        return java_vm_name;
    }

    public static String getJava_vm_vendor() {
        return java_vm_vendor;
    }

    public static String getJava_vm_version() {
        return java_vm_version;
    }

    /**
     * Set the file encoding to UTF-8
     */
    public static void setFile_encoding() {
        System.setProperty("file.encoding", "UTF-8");
    }

    /**
     * Get the file encoding from the System.
     *
     * @return String
     */
    public static String getFile_encoding() {
        return System.getProperty("file.encoding");
    }

    /**
     * Check if this OS is Windows.
     *
     * @return Boolean.
     */
    public static boolean isWindows() {
        if (getOs_name().contains("win")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Check if this OS is Mac.
     *
     * @return Boolean.
     */
    public static boolean isMac() {
        if (getOs_name().contains("mac")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Check if this OS is Linux.
     *
     * @return Boolean.
     */
    public static boolean isLinux() {
        if (getOs_name().contains("nux") || getOs_name().contains("nix")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Check if this OS is Linux and use Gnome Desktop.
     *
     * @return Boolean.
     */
    public static boolean isGnome() {
        if (!isLinux()) {
            return false;
        }
        String gdmSession = System.getenv("GDMSESSION");
        if ((gdmSession != null) && (gdmSession.toLowerCase().contains("gnome"))) {
            return true;
        }
        String desktopSession = System.getenv("DESKTOP_SESSION");
        if ((desktopSession != null) && (desktopSession.toLowerCase().contains("gnome"))) {
            return true;
        }
        String gnomeDesktopSessionId = System.getenv("GNOME_DESKTOP_SESSION_ID");
        return (gnomeDesktopSessionId != null) && (gnomeDesktopSessionId.trim().length() > 0);
    }

    /**
     * Check if this OS is Linux and use KDE Desktop.
     *
     * @return Boolean.
     */
    public static boolean isKDE() {
        if (!isLinux()) {
            return false;
        }
        String gdmSession = System.getenv("GDMSESSION");
        if ((gdmSession != null) && (gdmSession.toLowerCase().contains("kde"))) {
            return true;
        }
        String desktopSession = System.getenv("DESKTOP_SESSION");
        if ((desktopSession != null) && (desktopSession.toLowerCase().contains("kde"))) {
            return true;
        }
        String windowManager = System.getenv("WINDOW_MANAGER");
        return (windowManager != null) && (windowManager.trim().toLowerCase().endsWith("kde"));
    }

    public static boolean isjava_version_compatable() {
        if (getJava_version().startsWith("1.6") || getJava_version().startsWith("1.7")) {
            return true;
        } else {
            return false;
        }
    }
}